package com.nuoniu.sibanyun.mapper.crm;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.entity.crm.CrmLinkman;
import com.nuoniu.sibanyun.entity.crm.dto.NotTaskingLinkManSearchDto;
import com.nuoniu.sibanyun.userThread.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 客户联系人 Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-15
 */
@Component
@Mapper
public interface CrmLinkmanMapper extends BaseMapper<CrmLinkman> {

    /**
     * 修改所属客户
     * @author 小啊刚
     * @date 2020/6/22
     */
    @Update("update crm_linkman set crm_id = #{newCrmId}, crm_name = #{crmName}, update_user_id = #{userId}, update_user_name = #{realName}, update_date = now() where crm_id = #{crmId}")
    void updateCrmId(Integer crmId, Integer newCrmId, String crmName, Integer userId, String realName);

    /**
     * 根据客户获取联系人
     * @author 小啊刚
     * @date 2020/7/2
     */
    @Select("select * from crm_linkman where crm_id = #{crmId} and status != 1")
    List<Map> getByCrmId(Long crmId);

    /**
     *
     * @param companyId
     * @param userId
     * @return
     */
    Page<CrmLinkman> pageNotTaskingLinkMan(Page page,Integer companyId, Integer userId,@Param("dto") NotTaskingLinkManSearchDto notTaskingLinkManSearchDto);
    @Update("UPDATE crm_linkman SET is_main = IF(id=#{linkManId},1,0) WHERE company_id = #{companyId} AND crm_id = #{crmId}")
    void setKP(Integer companyId,Long linkManId, Long crmId);
}
